import Vue from "vue";
import VueRouter from "vue-router";
import Layout from '../views/Layout'
import Login from '../views/Login/Login.vue'
import register from '../views/Login/register.vue'

Vue.use(VueRouter)

const routes = [{
			path: '',
			redirect: '/login'
		},
		{
			path: '/login',
			name: 'Login',
			component: Login
		},
		{
			path: '/register',
			name: 'register',
			component: register
		},
		{
			path: '/home',
			component: Layout,
			children: [{
					path: '/home',
					name: 'home',
					component: () => import('../views/Home/index.vue')
				},
				{
					path: '/project',
					name: 'project',
					component: () => import('../views/Project/project.vue')
				},
				{
					path: '/interface',
					name: 'interface',
					component: () => import('../views/Interface/interface.vue')
				},
				{
					path: '/users',
					name: 'users',
					component: () => import('../views/Users/Users.vue')
				},
				{
					path: '/parameter',
					name: 'parameter',
					component: () => import('../views/Parameter/Parameter.vue')
				},
				{
					path: '/testcase',
					name: 'testcase',
					component: () => import('../views/Testcase/testcase.vue')
				},
				{
					path: '/interface-test',
					name: 'interface-test',
					component: () => import('../views/Interface-test/interface-test.vue'),
						children: [
							{
								path: '/interface-test/param',
								name: 'param',
								component: () => import('../views/Interface-test/param.vue'),
								meta: {
								      keepAlive: true // 需要被缓存
								    }
							},
							{
								path: '/interface-test/body',
								name: 'body',
								component: () => import('../views/Interface-test/body.vue'),
								meta: {
								      keepAlive: true // 需要被缓存
								    }
							},
							{
								path: '/interface-test/cookie',
								name: 'cookie',
								component: () => import('../views/Interface-test/cookie.vue'),
								meta: {
								      keepAlive: true // 需要被缓存
								    }
							}
						], redirect: '/interface-test/param'
					}
				]
			},

		]

		const router = new VueRouter({
			routes
		})


		//解决相同路径跳转报错问题

		const RouterPush = VueRouter.prototype.push
		VueRouter.prototype.push = function push(to) {
			return RouterPush.call(this, to).catch(err => err)
		}

		const RouterReplace = VueRouter.prototype.replace
		VueRouter.prototype.replace = function replace(to) {
			return RouterReplace.call(this, to).catch(err => err)
		}
		export default router
